package liumengbaio.lolzhangyoubao.Activity.Fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import liumengbaio.lolzhangyoubao.Activity.Adapter.ViewPager_AllHeroAroundAdapter;
import liumengbaio.lolzhangyoubao.Activity.InFo.FreeHeroInfo;
import liumengbaio.lolzhangyoubao.R;

/**
 * Created by lanouhn on 16/8/23.
 */
public class FragmentHeroPlay extends Fragment {
    private TabLayout tablayoutplay;
    private ViewPager viewPagerplay;
    private List<String> tabNames;
    private List<Fragment> fragments;
    private ViewPager_AllHeroAroundAdapter allHeroPlayAdapter;

    public static FragmentHeroPlay newInstants(FreeHeroInfo info) {
        FragmentHeroPlay fragmentHeroPlay = new FragmentHeroPlay();
        Bundle bundle = new Bundle();
        bundle.putSerializable("heroplayinfo",info);
        fragmentHeroPlay.setArguments(bundle);
        return fragmentHeroPlay;
    }
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_heroplay, null);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView(getView());
        initData();

    }


    private void initView(View view) {
        tablayoutplay= (TabLayout) view.findViewById(R.id.tab_hero_play);
        viewPagerplay= (ViewPager) view.findViewById(R.id.vp_hero_play);


    }
    private void initData() {
        tabNames=new ArrayList<>();
        tabNames.add("推荐玩法");
        tabNames.add("玩家发布");
        tabNames.add("自定义玩法");
        fragments=new ArrayList<>();
        FreeHeroInfo recommandinfo= (FreeHeroInfo) getArguments().getSerializable("heroplayinfo");
        FreeHeroInfo  playersinfo = (FreeHeroInfo) getArguments().getSerializable("heroplayinfo");
        FreeHeroInfo  custominfo = (FreeHeroInfo) getArguments().getSerializable("heroplayinfo");
        FragmentHerorecommendPlay recommendplay =FragmentHerorecommendPlay.newInstants(recommandinfo);
        fragments.add(recommendplay);
        FragmentHeroPlayerspublish playerspublish =FragmentHeroPlayerspublish.newInstants(playersinfo);
        fragments.add(playerspublish);
        FragmentHeroCustomPlay customplay =FragmentHeroCustomPlay.newInstants(custominfo);
        fragments.add(customplay);
        allHeroPlayAdapter =new ViewPager_AllHeroAroundAdapter(getFragmentManager(),tabNames,fragments);
        viewPagerplay.setAdapter(allHeroPlayAdapter);
        tablayoutplay.setupWithViewPager(viewPagerplay);

    }



}
